package com.srit.recipes.controller;

import com.srit.recipes.common.response.JpaPage;
import com.srit.recipes.common.response.Response;
import com.srit.recipes.entity.WeekRecipes;
import com.srit.recipes.entity.WeekRecipesDetail;
import com.srit.recipes.service.RecipesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@Api(tags = "菜谱数据")
public class RecipesController {

    @Autowired
    private RecipesService recipesService;

    @GetMapping("/recipes/recommend")
    @ApiOperation(value = "1 获取推荐菜谱", notes = "1基础 2减肥 3补钙")
    public Response recommend(int type) throws Exception {
        return Response.success(recipesService.recommend(type));
    }

    @GetMapping("/recipes/history")
    @ApiOperation(value = "2 历史食谱汇总数据")
    public Response recipesHistory(JpaPage jpaPage, WeekRecipes weekRecipes) {
        return Response.success(recipesService.recipesHistory(jpaPage, weekRecipes));
    }

    @GetMapping("/recipes/{id}")
    @ApiOperation("3 食谱详细数据")
    public Response currentRecipes(@PathVariable int id) {
        return Response.success(recipesService.currentRecipes(id));
    }

    @PostMapping("/recipes/save")
    @ApiOperation("4 保存推荐的食谱")
    public Response saveRecommend(@RequestBody List<WeekRecipesDetail> weekRecipes, int type) throws Exception {
        return Response.success(recipesService.saveRecommend(weekRecipes, type));
    }

    @PostMapping("/recipes/overview/addOrUpdate")
    @ApiOperation("5 添加或者修改食谱汇总数据, 修改就餐人数之类的， state： 0创建中 1: 审核中 2: 审核不通过 3: 审核通过， 4弃用")
    public Response addOrUpdateWeekRecipes(@RequestBody WeekRecipes weekRecipes) {
        return Response.success(recipesService.addOrUpdateWeekRecipes(weekRecipes));
    }

    @DeleteMapping("/recipes/overview/{id}")
    @ApiOperation("6 删除食谱")
    public Response deleteWeekRecipes(@PathVariable int id) {
        return Response.success(recipesService.deleteWeekRecipes(id));
    }

    @PostMapping("/recipes/detail/addOrUpdate")
    @ApiOperation("5.1 添加或者修改食谱中的菜品")
    public Response addOrUpdateDetail(@RequestBody WeekRecipesDetail recipesDetail) {
        return Response.success(recipesService.addOrUpdateDetail(recipesDetail));
    }

    @DeleteMapping("/recipes/detail/{id}")
    @ApiOperation("7 删除菜品， 用于删除食谱中不需要的才菜品")
    public Response deleteWeekRecipesDetail(@PathVariable int id) {
        return Response.success(recipesService.deleteWeekRecipesDetail(id));
    }

    @GetMapping("/recipes/list")
    @ApiOperation("8 查询菜品数据")
    public Response recipesList(String key, JpaPage page) {
        return Response.success(recipesService.recipesList(key, page));
    }

    @GetMapping("/recipes/examine/submit/{id}")
    @ApiOperation("9 提交审核")
    public Response submitRecipesExamine(@PathVariable int id) {
        return Response.success(recipesService.submitRecipesExamine(id));
    }


//    @PostMapping("/recipes/examine")
//    @ApiOperation("10 审核意见，通过或者不通过, 只需要传id， state，examineMsg三个字段；state： 0创建中 1: 审核中 2: 审核不通过 3: 审核通过")
//    public Response recipesExamine(@RequestBody WeekRecipes weekRecipes) {
//        return Response.success(recipesService.recipesExamine(weekRecipes));
//    }

//    @GetMapping("/recipes/examine/list")
//    @ApiOperation(value = "11 查询待审核食谱")
//    public Response recipesExamineList(JpaPage jpaPage) {
//        return Response.success(recipesService.recipesExamineList(jpaPage));
//    }
//
//    @GetMapping("/recipes/examine/pass")
//    @ApiOperation(value = "12 查询审核通过的食谱")
//    public Response recipesExaminePass(JpaPage jpaPage) {
//        return Response.success(recipesService.recipesExaminePass(jpaPage));
//    }








}
